package minSubsequence;

import java.util.*;

public class Solution {
    public List<Integer> minSubsequence(int[] nums) {
        // 排序 找到最大的两个数字或者三个数字或者k个数字返回满足条件的即可
        // 大顶堆实现 前k大的元素
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2-o1);
        int restSum = 0;
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
            restSum+=nums[i];
        }
        List<Integer> ans = new ArrayList<>();
        while(true){
            if(restSum>=sum){
                sum+=queue.peek();
                ans.add(queue.peek());
                restSum-=queue.poll();
            }else {
                return ans;
            }
        }
    }
}
